package com.xxwy.ddu.cms.manager.controller;

import com.xxwy.ddu.cms.authonrize.entity.BaseUser;
import com.xxwy.ddu.cms.authonrize.service.IUserService;
import com.xxwy.ddu.cms.manager.entity.Log;
import com.xxwy.ddu.common.util.RUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author xxwy
 * on 2018/9/18 0018
 */
@RestController
@RequestMapping("logInfo")
public class LogManagerController {

    @Autowired
    IUserService iUserService;

    @PostMapping("/log")
    public ResponseEntity insertLog(@AuthenticationPrincipal UserDetails userDetails, @RequestBody Log log){
        String username = userDetails.getUsername();
        BaseUser baseUser = iUserService.selectUserByName(username);
        if (baseUser != null) {
            log.setuId(baseUser.getuId());
        }
        log.setCreateTime(new Date());
        log.insert();
        return RUtil.success();
    }
}
